(function(window){
	var role={
	treeData:{},
	//渲染树形数据
	renderTreeNode:function(){
		var dataCode = $(this).attr("dataCode");
		if(Role.treeData && Role.treeData[dataCode]){
			Role.toggleNode(dataCode);
			return;
		}
		Role.loadAjax(dataCode, function(ds){
			var code = null;
			Role.treeData[dataCode] = ds;
			var nodeLi = [];
			nodeLi.push('<ul id="node_'+dataCode+'">');
			for(var i=0; i<ds.length; i++){
				code = ds[i]["roleCode"];
				nodeLi.push('<li>');
				nodeLi.push('<div id="root_'+code+'" class="topic">');
				nodeLi.push('<i id="rootIco_'+code+'" dataCode="'+code+'"></i>');
				nodeLi.push('<a href="sysRoleAction.do?method=query&parentCode='+code+'&roleLevel='+(ds[i]["roleLevel"]+1)+'" target="roleFrame">'+ds[i]["roleName"]+'</a>');
				nodeLi.push('</div>');
				nodeLi.push('</li>');
			}
			nodeLi.push('</ul>');
			$("#root_"+dataCode).append(nodeLi.join(""));
			$("#rootIco_"+code).click(Role.renderTreeNode);
			nodeLi = null;
			Role.toggleNode(dataCode);
		});
	},
	//渲染select数据
	renderSelectInfo:function(){
		var menuNode = $("#menuNode").val();
		//菜单节点，只需要配置基本数据
		if(menuNode=="1") return;
		var dataCode = $(this).val();
		//$("#menuFuncPart").removeClass("e_hide");
		$("#menuFuncPart").show();
		if(Role.treeData && Role.treeData[dataCode]){
			Role.createOption(Role.treeData[dataCode]);
			return;
		}
		Role.loadAjax(dataCode, function(ds){
			Role.treeData[dataCode] = ds;
			Role.createOption(ds);
		});
	},
	loadAjax:function(dataCode, callBackFunc){
		beginPageLoading();
		ajaxPost("sysRoleAction.do?method=load", "dataCode="+dataCode, function(data){
			endPageLoading();
			if(data["resultCode"] != 0){
				alert("数据加载异常");
				return;
			}
			callBackFunc(data["resultData"]);
		});
	},
	createOption:function(ds){
		var optionLi = [];
		for(var i=0; i<ds.length; i++){
			optionLi.push('<option value="'+ds[i]["dataCode"]+'">'+ds[i]["menuName"]+'</option>');
		}
		$("#parentCode").html(optionLi.join(""));
		optionLi = null;
		$("#parentCodeLi").removeClass("e_hide");
		$("#menuUrlLabel").addClass("e_label-required");
		$("#menuUrl").attr("nullable", "no");
	},
	toggleNode:function(dataCode){
		 $("#node_"+dataCode).slideToggle();
		 $("#root_"+dataCode).toggleClass("current");
	},
	//绑定tab事件
	bindTabEvent:function(menuId){
		
	}};
	window.Role=role;
})(window);

var windowCount = 0;

$(function(){
	// 模块选择下拉
	$(".c_tree .topic i").click(Role.renderTreeNode);
	
	$("#moduleType").change(Role.renderSelectInfo);
		
	
});


	